/*
 * @Date         : 2022-06-14 13:48:32
 * @LastEditors  : zu1662
 * @LastEditTime : 2022-07-04 22:59:54
 * @Description  : 用户详情数据输出序列化
 * 
 * Copyright © 2022 by zu1662, All Rights Reserved. 
 */
import { Exclude, Transform, Type } from "class-transformer";
import { UserRole } from "../user.interface";

export class UserDetailSerialization {
  @Type(() => String)
  readonly id: string;

  readonly name: string;

  readonly role: UserRole;

  readonly email: string;

  readonly avatar: string;

  @Transform(({ value }) => {
    // 隐藏 phone 中间四个字符
    const reg = /^(\d{3})\d{4}(\d{4})$/;  
    return value.replace(reg, "$1****$2");
  }, { toClassOnly: true })
  readonly phone: string;

  readonly status: 'locked' | 'active';

  @Exclude()
  readonly password: string;
  
  @Exclude()
  readonly type: string;

  readonly createdAt: Date;

  @Exclude()
  readonly updatedAt: Date;
}
